<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片视图 -->
        <el-card>
            <!-- 输入框 -->
             <el-input placeholder="请输入内容" v-model="orderlist.query" class="input-with-select" clearable @clear="getorderlist">
                <el-button slot="append" icon="el-icon-search" @click="getorderlist"></el-button>
            </el-input>
            <!-- table 表格 -->
            <el-table :data="orderData" style="width: 100%" border stripe>
                <!-- 索引列 -->
                <el-table-column type="index"></el-table-column>
                <el-table-column prop="order_number" label="订单编号"></el-table-column>
                <el-table-column prop="order_price" label="订单价格"></el-table-column>
                <el-table-column prop="pay_status" label="是否付款">
                    <template slot-scope="scope">
                        <el-tag type="danger" v-if="scope.row.pay_status === '0'">未付款</el-tag>
                        <el-tag type="success" v-else>已付款</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货"></el-table-column>
                <el-table-column prop="create_time" label="下单时间">
                    <template slot-scope="scope">{{scope.row.create_time | hendle_date}}</template>
                </el-table-column>
                <el-table-column prop="date" label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" icon="el-icon-edit" @click="operationDialog"></el-button>
                        <el-button type="success" size="mini" icon="el-icon-location" @click="logisticsDialog"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <!-- size-change	pageSize 改变时会触发	每页条数 -->
            <!-- current-change	currentPage 改变时会触发	当前页 -->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="orderlist.pagenum"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="orderlist.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="orderlisttotal">
            </el-pagination>
        </el-card>
        <!-- 操作对话框-->
        <el-dialog title="修改地址" :visible.sync="operationVisible" width="50%" @close="clearDialog">
            <!-- from 表单 -->
            <el-form :model="operationForm" :rules="operationRules" ref="operationFormRef" label-width="100px" class="demo-ruleForm">
                <el-form-item label="省市区/县" prop="address1">
                <!-- 级联选择器 -->
                    <el-cascader v-model="operationForm.address1" class="jilian" :options="cithData" :props="{ expandTrigger: 'hover' }"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="operationForm.address2"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="operationVisible = false">取 消</el-button>
                <el-button type="primary" @click="putDialog">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 物流显示对话框 -->
        <el-dialog title="提示" :visible.sync="logisticsVisible" width="30%">
            <!-- 假数据 -->
            <el-timeline :reverse="reverse">
                <el-timeline-item v-for="(activity, index) in activities" :key="index" :timestamp="activity.timestamp">
                {{activity.content}}
                </el-timeline-item>
            </el-timeline>
        </el-dialog>
    </div>
</template>
<script>
import cithData from './citydata.js'
    export default {
        data() {
            return {
                // table表格数据
                orderData:[],
                // 请求参数
                orderlist:{
                    query: '',
                    pagenum: 1,
                    pagesize: 10
                },
                // 当前页数
                orderlisttotal:0,
                // 操作对框框是否显示
                operationVisible: false,
                // 操作对框中的from表单数据
                operationForm: {
                    address1:[],
                    address2:''
                },
                // 操作对框中的from表单规则
                operationRules:{
                    address1:[
                        {required: true, message: '请输入内容', trigger: 'blur'}
                    ],
                    address2:[
                        {required: true, message: '请输入内容', trigger: 'blur'}
                    ]
                },
                // 级联选择器需要的数据
                cithData:cithData,
                // 物流显示对框框是否显示
                logisticsVisible: false,
                progressInfo:[],
                reverse: true,
                activities: [{
                content: '活动按期开始',
                timestamp: '2018-04-15'
                }, {
                content: '通过审核',
                timestamp: '2018-04-13'
                }, {
                content: '创建成功',
                timestamp: '2018-04-11'
                }]
            }
        },
        created() {
            this.getorderlist()
        },
        methods: {
            async getorderlist() {
                const {data: res} = await this.$http.get('orders',{params:this.orderlist})
                console.log(res);
                if(res.meta.status !== 200)return this.$message.error('获取订单数据列表失败')
                // console.log(res.data.goods);
                this.orderData = res.data.goods
                this.orderlisttotal = res.data.total
            },
            // 监听每页条数
            handleSizeChange(newsize) {
                // console.log(newsize);
                this.orderlist.pagesize = newsize
                this.getorderlist()
            },
            // 监听当前页
            handleCurrentChange(newcurrt) {
                // console.log(newcurrt);
                this.orderlist.pagenum = newcurrt
                this.getorderlist()
            },
            // 操作对话框
            operationDialog() {
                this.operationVisible = true
            },
            // 关闭操作对话框清空from表单数据
            clearDialog() {
                this.$refs.operationFormRef.resetFields()
            },
            // 点击操作对话框确定
            putDialog() {
                this.$refs.operationFormRef.validate(vali=>{
                    if(!vali)return
                    this.operationVisible = false
                })
            },
            // 物流显示对话框
            logisticsDialog() {
                // this.wuliu()
                this.logisticsVisible = true
            },
            // 获取物流函数  （后台获取不到）
            // async wuliu() {
            //     const {data: res} = await this.$http.get('kuaidi/1106975712662')
            //     console.log(res);
            //     if(res.meta.status !== 200){
            //         return this.$message.error(res.meta.msg)
            //     }
            //     this.progressInfo = res.data
            //     console.log(this.logisticsVisible);
            // }
        }
    }
</script>
<style lang="less" scope>
.jilian{
    width: 756px!important;
}
</style>